/**
 * Copyright (c) 2002-2008 jNETx.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNETx. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNETx.
 *
 * $Id: $
 *
 */
package com.pas.book;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;

/**
 * @author <a href="mailto:pshmarev@jnetx.ru">Paul Shmarev</a>
 * @version $Revision: $
 */
public class Win1251Reader extends Reader {

    private final InputStream stream;

    public Win1251Reader(InputStream stream) {
        this.stream = stream;
    }

    public int read(char[] cbuf, int off, int len) throws IOException {
        byte buf[] = new byte[len];
        int count = stream.read(buf, 0, len);
        for (int i = 0; i < count; i++) {
            cbuf[off + i] = CharCode.Win1251ToUnicode(buf[i]);
        }
        return count;
    }

    public void close() throws IOException {
        stream.close();
    }
}
